package edu.towson.cosc.cosc455.elugonjic.compiler;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
public class MyCompiler {

	static String token ="", input ="", file, convertedFile; 
	static boolean found;
	static MyLexicalAnalyzer lexer = new MyLexicalAnalyzer();
	static MySyntaxAnalyzer parser = new MySyntaxAnalyzer();
	static MySemanticAnalyzer generator = new MySemanticAnalyzer();
	static LexicalTokens lexicalTokens = new LexicalTokens();
	
	public static void main(String[] args) throws IOException{
		lexicalTokens.fillList();
		
		if(args.length != 1){
			System.err.println("There must be exactly one argument");
			System.exit(0);
		}
		else{
			file = args[0];
			if(!file.endsWith(".lol")){
				System.err.print("File must be of type .lol!");
				System.exit(0);
			}
			else{
				try {
			      FileReader fr = new FileReader(args[0]);
			      BufferedReader br = new BufferedReader(fr);
			      input = new Scanner(new File(args[0])).useDelimiter("\\Z").next();
			      convertedFile = input;
			      input = input.replace("\n", " ");
			      input = input.replace("\t", "").replace("\r", "");
			  	  lexer.start(input);
			      parser.lolcode();
			      if(parser.error == false)
			    	  generator.generate(convertedFile);
				}
		    catch(Exception e) {
		      System.out.println("Exception: " + e);
		    	}
			}
	
		}
	}
}

